feat: add measurement-validator module (Phase 1 & 2)#4
Draft
Conversation
Agent-Logs-Url: https://github.com/Himaan1998Y/pretext/sessions/3d85a02c-aa18-40cd-b13d-37f52bf0883c Co-authored-by: Himaan1998Y <210527591+Himaan1998Y@users.noreply.github.com>
…yout provider, docs Agent-Logs-Url: https://github.com/Himaan1998Y/pretext/sessions/3d85a02c-aa18-40cd-b13d-37f52bf0883c Co-authored-by: Himaan1998Y <210527591+Himaan1998Y@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add complete measurement validator implementation for Pretext
feat: add measurement-validator module (Phase 1 & 2)
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
src/measurement-validator/module that detects and classifies divergence between Pretext (canvas) and DOM text measurements, with multi-language fixture coverage and report generation.Core module (
src/measurement-validator/)types.ts—MeasurementSample,MeasurementResult,LineComparison,DivergenceAnalysis,SEVERITY_THRESHOLDS(exact< 0.1px,minor< 0.5px,major< 2.0px,critical≥ 2.0px)dom-adapter.ts— DOM measurement viaoffsetHeight/offsetWidth;measureLineWidthsreturns container width per line (Range-based per-line accuracy is a known follow-up)comparator.ts—MeasurementComparator.compare(sample, pretextLayout)→MeasurementResult;classifySeverity(delta)classifier.ts—classifyDivergencetests causes in priority order: font fallback (widths similar toserif→ font not loaded) → bidi shaping (RTL Unicode ranges) → emoji → browser quirk (Safari UA)test-suite.ts—TestSuiteaccepts an optionalLayoutProvidercallback so callers supply real Pretext layout; omitting it runs in DOM-only mode (all Pretext widths = 0)report-generator.ts—generateJSONReport,generateConsoleSummary,generateDetailedReport,generateLanguageBreakdownindex.ts— full public re-exportsTest fixtures (
test/fixtures/) — 29 samples, 13+ languagesenglish-samples.json(10),rtl-samples.json(5: Arabic/Hebrew/Urdu),cjk-samples.json(5: Chinese/Japanese/Korean),complex-script-samples.json(5: Thai/Myanmar/Khmer/Hindi),mixed-bidi-samples.json(4: mixed RTL+LTR)Tests (
test/)measurement-validator.test.ts— severity thresholds, report generators, fixture shape validation,MeasurementComparatorintegration (DOM mocked viaReflect.set)classifier.test.ts—detectBidi,detectEmoji,detectBrowserQuirk,classifyDivergencepass/diverge paths; UA-based quirk tests set and clean upglobalThis.navigatorDocs (
docs/)measurement-validator.md(API reference),classifier-guide.md(per-detector usage),language-matrix.md(support matrix + known limitations per script)Usage
Original prompt
Phase 1 & 2: Complete Measurement Validator Implementation
EXECUTIVE SUMMARY
Build a complete Measurement Validator module for Pretext that:
FILES TO CREATE - PHASE 1 & 2 COMBINED
CORE MODULE (src/measurement-validator/)
1. types.ts - All TypeScript interfaces
2. dom-adapter.ts - Browser DOM measurement
3. comparator.ts - Pretext vs DOM comparison
4. classifier.ts - Root cause detection
5. test-suite.ts - Multi-language test runner
6. report-generator.ts - Output formatting
7. index.ts - Public API exports
TEST SUITE (test/)
8. measurement-validator.test.ts - Phase 1 integration tests
9. classifier.test.ts - Phase 2 classifier tests
TEST FIXTURES (test/fixtures/)
10. english-samples.json - 10 English test cases
11. rtl-samples.json - 5 RTL test cases (Arabic, Hebrew, Urdu)
12. cjk-samples.json - 5 CJK test cases (Chinese, Japanese, Korean)
13. complex-script-samples.json - 5 complex script tests (Thai, Myanmar, Khmer)
14. mixed-bidi-samples.json - 4 mixed RTL/LTR test cases
DOCUMENTATION (docs/)
15. measurement-validator.md - Getting started + API reference
16. classifier-guide.md - How to use classifier + examples
17. language-matrix.md - Language support matrix + known issues
IMPLEMENTATION - ALL CODE READY TO PASTE
1. src/measurement-validator/types.ts
2. src/measurement-validator/dom-adapter.ts